package dr.incomeapp.bean;

import java.text.DateFormat;
import java.util.Date;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "INCOME")
public class IncomeBean extends Bean {
	
	public final static String BEANNAME="INCOMEBEAN";
	
	public static enum  TIMEEVENT {ONCE, DAY, WEEK, MONTH, YEAR}

	@DatabaseField(generatedId = true)
	protected long income_id =-1;
	
	
	@DatabaseField(foreign = true, columnName = "id", canBeNull = false ,foreignAutoCreate = true,foreignAutoRefresh = true)
	protected CategoryBean categoryBean;

	@DatabaseField
	protected String name;
	
	
	@DatabaseField
	protected String description;

	@DatabaseField
	protected float money;
	
	@DatabaseField
	protected float moneyProg;
	
	
	@DatabaseField
	protected boolean isCost = false;
	
	
	@DatabaseField
	protected Date startDate = new Date();
	
	@DatabaseField
	protected Date endDate = new Date();
	
	@DatabaseField
	protected TIMEEVENT enTimeEvent = TIMEEVENT.ONCE;

	public IncomeBean() {
		
	}
	
	

	public CategoryBean getCategoryBean() {
		return categoryBean;
	}



	public void setCategoryBean(CategoryBean categoryBean) {
		this.categoryBean = categoryBean;
	}



	public String getDescription() {
		return description;
	}



	public void setDescription(String description) {
		this.description = description;
	}



	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date date) {
		this.startDate = date;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date date) {
		this.endDate = date;
	}
	
	
	public long getId() {
		return income_id;
	}

	public void setId(long id) {
		this.income_id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public float getMoney() {
		if(isCost){
			return money * -1;
		}
		return money;
	}

	public void setMoney(float money) {
		this.money = money;
	}

	
	
	public boolean isCost() {
		return isCost;
	}

	public void setCost(boolean isCost) {
		this.isCost = isCost;
	}
	
	

	public float getMoneyProg() {
		if(isCost){
			return moneyProg * -1;
		}
		return moneyProg;
	}

	public void setMoneyProg(float moneyProg) {
		this.moneyProg = moneyProg;
	}


	public TIMEEVENT getTimeEvent() {
		return enTimeEvent;
	}

	public void setEnTimeEvent(TIMEEVENT enTimeEvent) {
		this.enTimeEvent = enTimeEvent;
	}

	@Override
	public String toString() {
		return "IncomeBean [id=" + income_id + ", name=" + name + ", cost=" + money
				+ "]";
	}
	
	public String getStartDateFormated(){
		 DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
		 
		 return df.format(getStartDate());
	}

	public String getEndDateFormated() {
		// TODO Auto-generated method stub
		 DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
		 
		 return df.format(getEndDate());
	}
	
	@Override
	public boolean equals(Object o) {
		if(o.getClass() == IncomeBean.class){
			IncomeBean inc = (IncomeBean)o;
			return this.income_id == inc.getId();
		}
		return false;
	}

}
